﻿Imports DTO
Imports System.Data.OleDb
Public Class CMonHocDAO

    Public Function ThemMonHoc(ByVal _MHdto As CMonHocDTO) As Integer
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strthemmonhoc = "insert into MONHOC(TenMonHoc) values('" + _MHdto.TenMonHoc + "')"
        Dim _cmd As New OleDbCommand(_strthemmonhoc, cnn)
        Dim _kt As Integer = _cmd.ExecuteNonQuery()
        cnn.Close()
        Return _kt
    End Function

    Public Function LayDanhSachMonHoc() As List(Of CMonHocDTO)
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strlaydsmonhoc = "select MaMonHoc,TenMonHoc from MONHOC "
        Dim _cmd As New OleDbCommand(_strlaydsmonhoc, cnn)
        Dim _dsmonhoc As New List(Of CMonHocDTO)
        Dim _reader As OleDbDataReader = _cmd.ExecuteReader()

        While _reader.Read()
            Dim _MHdto As New CMonHocDTO()
            _MHdto.MaMonHoc = _reader.GetInt32(0)
            _MHdto.TenMonHoc = _reader.GetString(1)
            _dsmonhoc.Add(_MHdto)
        End While
        cnn.Close()
        Return _dsmonhoc
    End Function

    Public Function CapNhatMonHoc(ByVal _MHdto As CMonHocDTO) As Integer
        Dim cnn As OleDbConnection = CDaTaProviderDAO.ConnectDB()
        cnn.Open()
        Dim _strcapnhat = "update MONHOC set TenMonHoc='" + _MHdto.TenMonHoc + "' where MaMonHoc=" + _MHdto.MaMonHoc.ToString() + ""
        Dim _cmd As New OleDbCommand(_strcapnhat, cnn)
        Dim _kt As Integer = _cmd.ExecuteNonQuery()
        cnn.Close()
        Return _kt
    End Function
End Class
